from flask import Flask, send_from_directory
import os
import socket

app = Flask(__name__)

# 设置静态文件目录（统一使用 'static' 和 'web' 目录）
app.static_folder = 'static'
app.template_folder = 'web'  # 明确指定模板目录

# 主路由 - 返回index.html
@app.route('/')
def serve_index():
    return send_from_directory(app.template_folder, 'index.html')

# 处理 /ai-chat 路由
@app.route('/ai-chat')
def serve_chat():
    return send_from_directory(app.template_folder, 'ai-chat.html')

# 静态文件路由（保持原有逻辑）
@app.route('/<path:path>')
def serve_static(path):
    if os.path.exists(os.path.join(app.static_folder, path)):
        return send_from_directory(app.static_folder, path)
    elif os.path.exists(os.path.join(app.template_folder, path)):
        return send_from_directory(app.template_folder, path)
    return "File not found", 404

if __name__ == '__main__':
    hostname = socket.gethostname()
    local_ip = socket.gethostbyname(hostname)
    print(f"服务已启动: http://{local_ip}:5000")
    app.run(host='0.0.0.0', port=5000, debug=True)